package com.ssx.cloud.controller;

import com.ssx.cloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Package com.ssx.cloud.controller
 * @ClassName PaymentController
 * @Copyright: Copyright (c) 2020
 * @Date 2020/11/21 22:14
 * @Company www.sudaoxi.com.cn
 * @Author 苏道羲
 * @Version 1.0
 * @Description
 */
@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/hystrix/ok/{id}")
    public String paymentinfo_OK(@PathVariable("id") Integer id){
        String result=paymentService.paymentinfo_OK(id);
        log.info("===result: "+result);
        return result;
    }

    @GetMapping("/hystrix/timeout/{id}")
    public String paymentinfo_Timeout(@PathVariable("id") Integer id){
        String result=paymentService.paymentinfo_Timeout(id);
        log.info("===result: "+result);
        return result;
    }

    /**
     * 服务熔断
     * @param id
     * @return
     */
    @GetMapping("/hystrix/circuit/{id}")
    public String paymentinfo_CircuitBreaker(@PathVariable("id") Integer id){
        String result=paymentService.CircuitBreaker(id);
        log.info("===result: "+result);
        return result;
    }
}
